# class House():
#
#     def __init__(self,housetype,area,furniture=[]):
#         self.housetype = housetype
#         self.area = area
#         self.furuniture = []
#     def add(self,furniture):
#         if self.area >= furniture.area:
#             self.furuniture.append(furniture)
#             self.area -= furniture.area
#             print(f"{furniture.name}已经添加到房子中")
#         else:
#             print(f"房子剩余面积不足，无法添加{furniture.name}")
#     def display(self):
#         print("户型",self.housetype)
#         print("总面积",self.area,"平米")
#         print("剩余面积",self.area,"平米")
#         print("家具名称：")
#         for furniture in self.furuniture:
#             print(furniture.name)
#
#
# class Furniture:
#     def __init__(self,name,area):
#         self.name = name
#         self.area = area
#
# bed = Furniture("床",4)
# wardrobe = Furniture("衣柜",2)
# table = Furniture("餐桌",1.5)
#
# my_house = House("两居室",120)
# my_house.add(bed)
# my_house.add(wardrobe)
# my_house.add(table)
#
# my_house.display()
#


# def forg(n):
#     if n == 1 :
#         return 1
#     if n == 2 :
#         return 2
#     return forg(n-1) + forg(n-2)
# print(forg(10))

# class Book:
#     def __init__(self,title,author,date):
#         self.title = title
#         self.author = author
#         self.date = date
#     def display(self):
#         print("信息",self.title)
#         print("作者",self.author)
#         print("出版日期",self.date)
# class Library:
#     def __init__(self):
#         self.books = []
#     def add_book(self, book):
#         """
#         添加图书到图书馆的图书列表中
#         """
#         self.books.append(book)
#     def borrow_book(self,title):
#         """
#         根据书名借出图书，如果找到对应书名的图书，则从图书列表中移除，并返回该图书对象
#         """
#         flag = True
#         for item in self.books:
#             if item.title == title:
#                 flag = False
#                 self.books.remove(item)
#         if flag:
#             print(f"没有借的这本{title}书")
#     def return_book(self,book):
#         """
#                显示当前图书馆中所有图书的书名、作者和出版日期
#         """
#         self.books.append(book)
#
#     def show_books(self):
#         for book in self.books:
#             print("=" * 100)
#             print("书名",book.title)
#             print("作者",book.author)
#             print("出版日期",book.date)
#             print("=" * 100)
#
# library = Library()
#
# book1 = Book("Python编程入门", "张三", "2021-01-01")
# book2 = Book("Java编程基础", "李四", "2021-02-01")
# book3 = Book("C++高级编程", "王五", "2021-03-01")
#
# library.add_book(book1)
# library.add_book(book2)
# library.add_book(book3)
#
# library.show_books()
#
# library.borrow_book('C++高级编程')
# library.show_books()
# library.return_book(book3)
# print("还书之后列表：")
# library.show_books()

# class Anamial():
#     def __init__(self,name,age):
#         self.name = name
#         self.age = age
#     def make_sound(self):
#         pass
# class Dog(Anamial):
#     def __init__(self,name,age,color):
#         super().__init__(name,age)
#         # self.name = name
#         # self.age = age
#         self.color = color
#     def make_sound(self):
#         print("汪汪汪。。。")
# d = Dog("哈士奇",3,"白色")
# print(d.name)
# print(d.age)
# print(d.color)
# d.make_sound()

# import queue
# q = queue.Queue()
# for i in range(5):
#     q.put(i)
#     print(q.qsize())
# while not q.empty():
#     print(q.get())
#
# class QueueUsingList:
#     def __init__(self):
#         self.queue = []
#     #入队
#     def enqueue(self,item):
#         self.queue.append(item)
#     #检查列表是否为空
#     def is_empty(self):
#         return  len(self.queue) == 0
#     #出队
#     def dequeue(self):
#     #如果列表不为空
#         if not self.is_empty():
#             return self.queue.pop(0)
#         else:
#             return '队列为空'
#
#     #查看队首元素
#     def peek(self):
#         #判断队列是否为空
#         if not self.is_empty():
#             return self.queue[0]
#         return None
#     def size(self):
#         return len(self.queue)
#
# Q = QueueUsingList()
#
# for i in range(5):
#     Q.enqueue(i*100)
# # print(Q.size())
# # while not Q.is_empty():
# #     print(Q.dequeue())
# print(Q.dequeue())
# print(Q.dequeue())
# print(Q.dequeue())
# print(Q.dequeue())
# print(Q.peek())
# print(Q.peek())
# print(Q.peek())

# def jiecheng(n):
#     if n == 1:
#         return 1
#     if n ==2 :
#         return 2
#     return jiecheng(n-1)*n
# print(jiecheng(6))

# class Stack:
#     def __init__(self):
#         self.items = []
#      #压栈
#     def push(self,item):
#         self.items.append(item)
#
#     def is_empty(self):
#         return len(self.items) == 0
#     #弹栈
#     def pop(self):
#         if not self.is_empty():
#             return self.items.pop()
#         return None
#     #查看栈顶元素
#     def peek(self):
#         if not self.is_empty():
#             return self.items[-1]
#         return None
#     def size(self):
#         return len(self.items)
# def simulate_function_call():
#     call_stack = Stack()
#     function = ['func1','func2','func3']
#     for func in function:
#         call_stack.push(func)
#
#     while not call_stack.is_empty():
#         current_function = call_stack.pop()
#         print(f"函数执行结束：{current_function}")
#     print("函数调用结束")
# simulate_function_call()
#
# def is_parentheses_balanced(expression):
#     stack = Stack()
#     pairs = {')':'('}
#     for char in expression:
#         if char in pairs.values():
#             stack.push(char)
#         elif char in pairs.keys():
#             if stack.is_empty() or stack.pop() !=pairs[char]:
#                 return False
#     return stack.is_empty()
# expressions = ["(())", "((()))", "(()", ")(", "(a + b) * (c - d)"]
# for expr in expressions:
#     print(f"表达式 '{expr}' 的括号匹配: {is_parentheses_balanced(expr)}")
def singleton(fun):

    cls = {}  # 用于存储类的实例

    def inner_method(*args, **kwargs):
        if fun not in cls:
            obj = fun(*args, **kwargs)
            cls[fun] = obj
            return obj
        return cls[fun]
    return inner_method


@singleton
class Connect():

    def __init__(self, host):
        self.host = host

    def get_connect(self):
        return self.host


c = Connect('155.124.10.5')
c2 = Connect('155.124.10.6')
print(id(c))
print(id(c2))
print(c2.get_connect())
print(c.get_connect())
